package com.tencent.matrix.trace.core;

import android.os.Build;
import android.os.Looper;
import android.os.MessageQueue;
import android.os.SystemClock;

import com.tencent.matrix.g.Matrix_G_F;

import java.util.HashSet;
import java.util.Objects;

public class Trace_Core_A implements MessageQueue.IdleHandler {
    private static final Trace_Core_A cEa = new Trace_Core_A();
    public final HashSet<Trace_Core_A.a> listeners;
    private long cDZ;
    private Looper cDY;

    private Trace_Core_A() {
        this(Looper.getMainLooper());
    }

    public Trace_Core_A(Looper looper) {
        this.listeners = new HashSet();
        this.cDZ = 0;
        Objects.requireNonNull(looper);
        this.cDY = looper;
        Ic();
        c(looper);
    }

    private synchronized void c(Looper looper) {
        if (Build.VERSION.SDK_INT >= 23) {
            looper.getQueue().addIdleHandler(this);
        } else {
            try {
                ((MessageQueue) Matrix_G_F.a(looper.getClass(), "mQueue", looper)).addIdleHandler(this);
            } catch (Exception e) {
            }
        }
    }

    public static abstract class a {
        boolean cEc = false;

        public boolean isValid() {
            return false;
        }

        public void dispatchStart() {
        }

        public void dG(String str) {
            this.cEc = true;
            dispatchStart();
        }

        public void dispatchEnd() {
        }
    }

    public static void a(a aVar) {
        Trace_Core_A aVar2 = cEa;
        synchronized (aVar2.listeners) {
            aVar2.listeners.add(aVar);
        }
    }

    @Override
    public boolean queueIdle() {
        if (SystemClock.uptimeMillis() - this.cDZ >= 60000) {
            Ic();
            this.cDZ = SystemClock.uptimeMillis();
        }
        return true;

    }

    static void b(Trace_Core_A.a aVar) {
        Trace_Core_A aVar2 = cEa;
        synchronized (aVar2.listeners) {
            aVar2.listeners.remove(aVar);
        }
    }

    private synchronized void Ic() {

    }
}